<div id="make-invoice">
<?php
	$invoice = $this->invoice;
	$performaInvoice = $invoice->performainvoice;
	echo link_to('Performa Invoice ID: '.$performaInvoice->id, array('action' => 'performaInvoice', 'id' => $performaInvoice->id));
?>
</div>
<div id="print-header">
	<div id="proforma-id">
		<h2>Invoice</h2>
		<?php echo 'Invoice No: ', $invoice->id, '<br />'; ?>
	</div>
	<h1>Game City</h1>
	15C Whalley Close,<br />Kingston 6.
</div>
<div id="performa-customer-info-container">
	<div id="performa-info">
		Date: <?php echo strftime('%e %B %Y', strtotime($invoice->created_date)); ?><br />
		Rep: Mr. A.M.Ishaq<br />
		Phone: 422-1353
	</div>
	<div id="customer">
		Customer:<br />
		<?php
		echo (($performaInvoice->address_to) ? $performaInvoice->address_to : $performaInvoice->customer->user->full_name()),',<br />',
			(!empty($performaInvoice->customer->user->company_name)) ? ucfirst($performaInvoice->customer->user->company_name).',<br />' : '',
			$performaInvoice->customer->user->address();

		if ($performaInvoice->attention) { echo '<br />Attention: ', $performaInvoice->customer->user->full_name(); }

		?>
	</div>
</div>
<div id="order-specificications">
	<div id="order-headings">
		<div class="quantity"><b>Quantity</b></div>
		<div class="price"><b>Total Price</b></div>
		<div class="description"><b>Product Description</b></div>
	</div>
	<?php
		$sub_total = 0.00;
		foreach ($performaInvoice->orderdetails as $order) {
			$quantity = $order->quantity;
			$price = $order->price;
			$mounting_price = $order->mounting_price;
			$isMounting = $mounting_price > -1;
			$sub_total += $quantity * (($isMounting) ? ($mounting_price + $price) : ($price));
			$product = $order->product;
			echo '<div class="order-row">
					<div class="product-row">
						<div class="quantity">',
							$quantity,
						'</div>
						<div class="price">',
							($quantity > 1) ? (number_to_currency($price * $quantity) . '<br />(' . number_to_currency($price) . ' each)') : number_to_currency($price),
						'</div>
						<div class="description"><b>',
							link_to($product->name, array('action' => 'viewProduct', 'id' => $product->id)),'</b><br />Item#: ',
							$product->id,
						'</div>
					</div>
					<div class="mounting-row">
						<div class="price">',
							($isMounting) ? (($quantity > 1) ? (number_to_currency($mounting_price * $quantity) . '<br />(' . number_to_currency($mounting_price) . ' each)') : number_to_currency($mounting_price)) : 'Not requested',
						'</div>
						<div class="description">
							Mounting
						</div>
					</div>
				</div>';
		}
		$grand_total = $sub_total;
		/*
		if (is_numeric($transport_price = ($performaInvoice->transport_price > -1) ? $performaInvoice->transport_price : 'Not requested')) {
			$grand_total += $transport_price;
			$transport_price = number_to_currency($transport_price);
		}
		*/
		if ($transport_price = ($performaInvoice->transport_price > 0) ? $performaInvoice->transport_price : false) {
			$grand_total += $transport_price;
			$transport_price = number_to_currency($transport_price);
		}
		$grand_total -= ($discount_isset = (($discount = $performaInvoice->discount) > -1)) ? $discount : 0.0;
		echo '<div id="totals">
				<div id="sub-total">
					<div class="price">',
						number_to_currency($sub_total),
					'</div>
					<b>Subtotal</b>
				</div>';
				if ($transport_price) {
					echo
					'<div id="transport">
						<div class="price">',
							$transport_price,
						'</div>
						<b>Transport</b>
					</div>';
				}
		if ($discount_isset) {
			echo '<div id="discount">
					<div class="price">- ',
						number_to_currency($discount),
					'</div>
					<b>Discount</b>
				</div>';
		}
		echo '<div id="grand-total">
					<div class="price">',
						number_to_currency($grand_total),
					'</div>
					<b>Grand Total</b>
				</div>';
		if ($invoice->deposit_recieved > 0) {
			echo '<div id="deposit-recieved">
					<div class="price">- ',
						number_to_currency($invoice->deposit_recieved),
					'</div>
					<b>Deposit Recieved</b>
				</div>';
			echo '<div id="balance-due">
					<div class="price">',
						number_to_currency($grand_total - $invoice->deposit_recieved),
					'</div>
					<b>Balance Due</b>
				</div>';
		}
		echo '</div>';
	?>
</div>
